//
//  AddViewController.m
//  08-UI
//
//  Created by Mars_ZXB on 16/7/25.
//  Copyright © 2016年 BAT3. All rights reserved.
//

#import "AddViewController.h"

@interface AddViewController ()
@property (nonatomic, strong) NSMutableDictionary *dictionary;
@property (nonatomic, strong) UITextField *textOfName;
@property (nonatomic, strong) UITextField *textOfAge;
@property (nonatomic, strong) UITextField *textOfGender;
@property (nonatomic, strong) UITextField *textOfPhoneNumber;

@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    self.dictionary = [NSMutableDictionary dictionary];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(10, 200, 200, 30);
    button.backgroundColor = [UIColor greenColor];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(handleButton:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"添加" forState:UIControlStateNormal];
    
    UILabel *labelOfName = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, 150, 30)];
    UILabel *labelOfGender = [[UILabel alloc] initWithFrame:CGRectMake(10, 90, 150, 30)];
    UILabel *labelOfPhoneNumber = [[UILabel alloc] initWithFrame:CGRectMake(10, 130, 150, 30)];
    UILabel *labelOfAge = [[UILabel alloc] initWithFrame:CGRectMake(10, 170, 150, 30)];
    labelOfName.text = @"Name:";
    labelOfAge.text = @"Age:";
    labelOfGender.text = @"gender:";
    labelOfPhoneNumber.text = @"phoneNumber:";
    
    [self.view addSubview:labelOfPhoneNumber];
    [self.view addSubview:labelOfAge];
    [self.view addSubview:labelOfGender];
    [self.view addSubview:labelOfName];
    
    self.textOfName = [[UITextField alloc] initWithFrame:CGRectMake(170, 50, 200, 30)];
    self.textOfAge = [[UITextField alloc] initWithFrame:CGRectMake(170, 170, 200, 30)];
    self.textOfGender = [[UITextField alloc] initWithFrame:CGRectMake(170, 90, 200, 30)];
    self.textOfPhoneNumber = [[UITextField alloc] initWithFrame:CGRectMake(170, 130, 200, 30)];
    
    self.textOfName.placeholder = @"请输入姓名";
    self.textOfAge.placeholder = @"请输入年龄";
    self.textOfGender.placeholder = @"请输入性别";
    self.textOfPhoneNumber.placeholder = @"请输入电话号码";
    
    [self.view addSubview:self.textOfPhoneNumber];
    [self.view addSubview:self.textOfGender];
    [self.view addSubview:self.textOfAge];
    [self.view addSubview:self.textOfName];
    
}
- (void)handleButton:(UIButton *)button
{
    if (self.textOfName.text != nil && self.textOfAge.text != nil && self.textOfGender.text != nil && self.textOfPhoneNumber.text != nil) {
        
        [self.dictionary setObject:self.textOfName.text forKey:@"name"];
        [self.dictionary setObject:self.textOfGender.text forKey:@"gender"];
        [self.dictionary setObject:self.textOfPhoneNumber.text forKey:@"phoneNumber"];
        [self.dictionary setObject:self.textOfAge.text forKey:@"age"];
    }
    NSLog(@"%@", self.dictionary);
    if (self.delegate && [self.delegate respondsToSelector:@selector(addContact:)]) {
        [self.delegate addContact:self.dictionary];
    }
    
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
